package br.com.solrtools.controller;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import br.com.solrtools.bean.SolrQueryBean;
import br.com.solrtools.service.QueryServiceImpl;

public class AdminQuery {

	private SolrQueryBean solrQuery;
        private List<String> listQuery;
	
	
	public AdminQuery() {
		solrQuery = new SolrQueryBean();
	}
	
	public void cadastrar() {
		FacesContext context = FacesContext.getCurrentInstance();
		String mensagem="";
		
		if(getSolrQuery().getQuery().trim().equals("")){
			mensagem="Passou";
		}else{
			mensagem="não passou";
		}
		FacesMessage message = new FacesMessage (mensagem);
		context.addMessage("formulario", message);
	}

        /**
         * Metodo da classe controller responsssavel por buscar os dados de todos os itens no solr
         * @return List<String>
         */
        public List<String> searchAll(){
            FacesContext context = FacesContext.getCurrentInstance();
            String mensagem="Funciona";
            
            QueryServiceImpl queryService = new QueryServiceImpl();
            
            FacesMessage message = new FacesMessage (mensagem);
	    context.addMessage("formulario", message);
            try {
               listQuery = queryService.searchAll();
            } catch (Exception ex) {
                Logger.getLogger("Metodo listaTodos " + AdminQuery.class.getName()).log(Level.SEVERE, null, ex);
            }
            return listQuery;
        }
        
	public SolrQueryBean getSolrQuery() {
		return solrQuery;
	}

	public void setSolrQuery(SolrQueryBean solrQuery) {
		this.solrQuery = solrQuery;
	}

    /**
     * @return the listQuery
     */
    public List<String> getListQuery() {
        return solrQuery.getListQuery();
    }

    /**
     * @param listQuery the listQuery to set
     */
    public void setListQuery(List<String> listQuery) {
        this.listQuery = listQuery;
    }

 
	
	
}